<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <div id="app">
        <h3>Vue中使用Echarts</h3>
        <div>
            <p>
                <input v-model="brand" type="text">
            </p>
            <p>
                <input v-model.number="num" type="text">
            </p>
            <button @click="add">添加</button>
        </div>
        <div ref="main" style="width: 600px;height:500px;"></div>
    </div>


    <script src="./js/vue.js"></script>
    <script crossorigin="anonymous"
        integrity="sha512-hjx+SPhu1qxXHVo0A5AfAiso7QfjsF59qQVEbNgLpef2vwPJsiWd9Mv5ms0TNHFlRETxIaWzbN3WaSYbt+2aLQ=="
        src="https://lib.baomitu.com/echarts/5.2.0/echarts.common.js"></script>
    <script>

        new Vue({
            el: "#app",
            data() {
                return {
                    brand: "",
                    num: "",
                    xList: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'],
                    xData: [5, 20, 36, 10, 15, 20]
                }
            },
            methods: {
                add() {
                    this.xList.push(this.brand)
                    this.xData.push(this.num)
                    this.init()
                },
                init() {
                    let MyEcharts = echarts.init(this.$refs.main)
                    // 指定图表的配置项和数据
                    var option = {
                        title: {
                            text: 'ECharts 入门示例'
                        },
                        tooltip: {},
                        legend: {
                            data: ['销量']
                        },
                        xAxis: {
                            data: this.xList
                        },
                        yAxis: {},
                        series: [
                            {
                                name: '销量',
                                type: 'bar',
                                data: this.xData
                            }
                        ]
                    }
                    MyEcharts.setOption(option)
                }
            },
            mounted() {
                this.init()
            }
        })
    </script>
</body>

</html>